/****************************************************************
 *  This file created by writerB.php on 04/19/2007 at 13:16:40  *
 ****************************************************************
 *  writerB.php created by Tonk (tonk@ctonk.com) in 2007        *
 ****************************************************************
 *                 General Document Information
 *
 *  File Name: loginHandler.h
 *  Class Names: LoginHandler, LoginList
 *  Parent Classes: none
 *  Data members: 5
 *  Notes:
 ****************************************************************/

#ifndef __H_LOGINHANDLER
#define __H_LOGINHANDLER

#include <iostream>
#include <vector>
#include "account.h"
#include "combined.h"
#include "definitions.h"



class LoginHandler {
	protected:
		// Protected data...
		int			_LoginHandlerID;	// Holds a unique value for every instantiation.
		std::string	_name;
		std::string	_output;
		Character*	_character;
		unsigned	_state;
		unsigned	_flags;

		// Protected methods...
		void	setLoginHandlerID( const int& LoginHandlerID );
		bool	checkName( Character* character, const std::string& input );
		bool	checkPassword( Character* character, const std::string& input );

	public:
		// Constructors...
		LoginHandler();
		LoginHandler( Character* character );
		LoginHandler( const LoginHandler& );	// Doesn't change _LoginHandlerID
		~LoginHandler();

		// Operators...
		LoginHandler& operator = ( const LoginHandler& );		// Doesn't change _LoginHandlerID
		bool operator == ( const LoginHandler& ) const;	// Doesn't compare _LoginHandlerIDs
		bool operator < ( const LoginHandler& ) const;	// Compares _LoginHandlerIDs
		bool operator > ( const LoginHandler& ) const;	// Compares _LoginHandlerIDs

		// Public accessor methods...
		int			getLoginHandlerID( void ) const;
		void		setName( const std::string& name );
		std::string	getName( void ) const;
		void		setOutput( const std::string& output );
		std::string	getOutput( void ) const;
		void		setCharacter( Character* character );
		Character*	getCharacter( void ) const;
		void		setState( const unsigned& state );
		unsigned	getState( void ) const;
		void		setFlags( const unsigned& flags );
		unsigned	getFlags( void ) const;

		// General methods...
		bool		fire( Character* character, const std::string& args );

		// Static data...
		static int	loginHandlerIndex;	// Used to create a unique id for every LoginHandler object
		static int	numLoginHandlers;	// Keeps track of the total number of LoginHandler objects

		// Static methods...
};

// Associated operators...
std::ostream& operator << ( std::ostream&, const LoginHandler& );
std::ostream& operator << ( std::ostream&, const LoginHandler* );

///////////////////////////////////////////////////////  LOGIN LIST  ///////////////////////////////////////////
class LoginList {
	protected:
		// Protected data...
		std::vector< LoginHandler* >	_handlers;
		std::vector< Account* >			_register;

		// Protected methods...
		void		load( void );	// Read the register from file
		void		save( void );	// Write the register to file

	public:
		// Constructors...
		LoginList( void );
		~LoginList( void );

		// Public accessor methods...
		std::vector< LoginHandler* >&	getHandlers( void );
		std::vector< Account* >&		getRegister( void );

		// General methods...
		void		add( const std::string& name, const std::string& password );	// Add a player to the register
		void		drop( const std::string& name );								// Drop a player from the register
		bool		found( const std::string& name );								// Check for a player in the register
		void		act( Character* c, const std::string& input );

		// Static methods...
		static LoginList&	Instance();
};

inline LoginList& LoginList::Instance() { // static
	static LoginList _instance;
	return _instance;
}



#endif // __H_LOGINHANDLER
